function loadJS(url, callback = function() {}) {
	const script = document.createElement('script')
	script.type = 'text/javascript';
	//IE
	if (script.readyState) {
		script.onreadystatechange = function() {
			if (script.readyState == 'loaded' || script.readyState == 'complete') {
				script.onreadystatechange = null;
				callback();
			}
		};
	} else {
		//其他浏览器
		script.onload = function() {
			callback();
		};
	}
	script.src = url;
	document.getElementsByTagName('head')[0].appendChild(script);
}

/**
 * 动态加载CSS
 * @param {string} url 样式地址
 */
function loadCss(url) {
	var head = document.getElementsByTagName('head')[0];
	var link = document.createElement('link');
	link.type = 'text/css';
	link.rel = 'stylesheet';
	link.href = url;
	head.appendChild(link);
}

function loadJSList(urls, callback = function() {}) {
	let index = 0;

	function fun() {
		let url = urls[index++];
		if (!url) {
			callback();
			return;
		}
		loadJS(url, fun);
	}

	fun();
}

export default {
	loadJS,
	loadJSList,
	loadCss
}
